package com.nike.amoeba.bean.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.nike.amoeba.bean.db.MainDrawerBean
import com.nike.amoeba.bean.db.UploadOrderBean
import kotlinx.coroutines.flow.Flow

/**
 * @Author nike
 * @Date 2023/7/28 10:34
 * @Description
 */
@Dao
interface MainDrawerDao {

    /**
     * 增加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun add(vararg bean: MainDrawerBean)

    /**
     * 删除
     */
    @Delete
    suspend fun delete(bean: MainDrawerBean)

    //删除数据库表全部数据
    @Query("delete from MainDrawerBean")
    suspend fun deleteAll()

     /**
     * 查询所有
     */
    @Query("SELECT * FROM MainDrawerBean")
    fun findAll(): List<MainDrawerBean>

    /**
     * 根据用户查询所有
     */
    @Query("SELECT * FROM MainDrawerBean WHERE userId =:roNo AND companyId =:companyId")
    fun findAll(roNo: String, companyId: String): Flow<List<MainDrawerBean>>

    /**
     * 更新
     */
    @Update
    fun update(bean: MainDrawerBean)


    suspend fun insertOrUpdate(bean: MainDrawerBean) {
        if (bean == null){
            add(bean)
        }else{
            update(bean)
        }
    }

}